package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.product.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "测试控制器")
@RestController
@RequestMapping("admin/product/test")
public class TestController {
    @Autowired
    private TestService testService;

    @ApiOperation("测试登录")
    @GetMapping("testLogin")
    public String testLogin(HttpServletRequest request){
        String userId = AuthContextHolder.getUserId(request);
        String userTempId = AuthContextHolder.getUserTempId(request);
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println("cookie.getValue() = " + cookie.getValue());
        }
        return "userId:"+userId+"。\tuserTempId:"+userTempId;
    }

    @ApiOperation(value = "本地锁的局限性")
    @GetMapping("testLock")
    public Result testLock(){
        testService.testLock();
        return Result.ok();
    }

    @ApiOperation(value = "读写锁的读接口")
    @GetMapping("read")
    public Result read(){
        String msg = testService.readLock();
        return Result.ok(msg);
    }

    @ApiOperation(value = "读写锁的写接口")
    @GetMapping("write")
    public Result write(){
        String msg = testService.writeLock();
        return Result.ok(msg);
    }

    /*@ApiOperation("测试Objece未实现序列化,测试redis获取数据")
    @GetMapping("testGetObject")
    public Object testGetObject(){
        Student student = testService.testGetObject();
        //return Result.ok(student);
        //Object o = testService.testGetObject();
        return student;
    }*/

}

